﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.Configuration;

using System.Configuration;
using System.Net;
using System.Collections.Specialized;
using System.Diagnostics;


using MySql.Data;
using MySql.Data.MySqlClient;

namespace doris.Ticketuser
{
    public partial class comfirmEditUser : System.Web.UI.Page
    {
        MySqlConnection con;
        MySqlCommand cmd;

        protected void Page_Load(object sender, EventArgs e)
        {
            this.setConnection();
            String fullname = Session["fullname"].ToString();
            String adress   = Session["adress"].ToString();
            String email    = Session["email"].ToString();
            String postcode = Session["postcode"].ToString();
            String username = Session["username"].ToString();
            

            try
            {
                con.Open();
                cmd = new MySqlCommand("UPDATE user SET Fullname=@fullname, Email=@email," +
                                       "Postcode=@postcode, Adress=@adress "
                                        + "WHERE Username=@username", con);
                
                
                cmd.Parameters.AddWithValue("@username", username);
                cmd.Parameters.AddWithValue("@fullname", fullname);
                cmd.Parameters.AddWithValue("@email",  email);
                cmd.Parameters.AddWithValue("@postcode", postcode);
                cmd.Parameters.AddWithValue("@adress", username);
                cmd.ExecuteNonQuery();

                Label1.Text = "Data for " + username + " " + "has been updated";

                Label2.Text = username;
                Label3.Text = fullname;
                Label4.Text = email;
                Label5.Text = postcode;
                Label6.Text = adress;

            }

            catch (Exception ex)
            {
                Label1.Text = ex.ToString();

            }
            finally
            {
                con.Close();
            }
        }

        public void setConnection()
        {
            con = new MySqlConnection(WebConfigurationManager.ConnectionStrings["localConnectionString"].ConnectionString);
        }


        protected void OkButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("userMain.aspx");
        }
    }
}